// 1629. 按键持续时间最长的键
/**
 * @param {number[]} releaseTimes
 * @param {string} keysPressed
 * @return {character}
 */
var slowestKey = function (releaseTimes, keysPressed) {
    let max = releaseTimes[0], result = keysPressed.charAt(0)
    for (let i = 1; i < releaseTimes.length; i++) {
        const temp = releaseTimes[i] - releaseTimes[i - 1]
        if (temp > max || (temp === max && result < keysPressed[i])) {
            max = temp
            result = keysPressed[i]
        }
    }
    return result
};
var slowestKey = function (releaseTimes, keysPressed) {
    const n = releaseTimes.length;
    let ans = keysPressed[0];
    let maxTime = releaseTimes[0];
    for (let i = 1; i < n; i++) {
        const key = keysPressed[i];
        const time = releaseTimes[i] - releaseTimes[i - 1];
        if (time > maxTime || (time === maxTime && key > ans)) {
            ans = key;
            maxTime = time;
        }
    }
    return ans;
};

slowestKey([23, 34, 43, 59, 62, 80, 83, 92, 97], "qgkzzihfc")